Fix QNN runner KV cache bitwidth detection in Android JNI#18731
Closed
abhinaykukkadapu wants to merge 1 commit intomainfrom
Closed
Fix QNN runner KV cache bitwidth detection in Android JNI#18731abhinaykukkadapu wants to merge 1 commit intomainfrom
abhinaykukkadapu wants to merge 1 commit intomainfrom
Conversation
Summary: The QNN runner in the Android JNI layer was hardcoded to use Runner<uint16_t>, but models can be exported with either 8-bit or 16-bit KV caches. This mismatch caused the KV cache data to be misinterpreted, resulting in gibberish output in the Android demo app while the same model worked correctly via the CLI runner. This change mirrors the dynamic KV bitwidth detection already present in qnn_llama_runner.cpp by querying the model's get_kv_io_bit_width method and instantiating the correct Runner<uint8_t> or Runner<uint16_t> accordingly. Also passes temperature_ to the Runner constructor which was previously omitted. Fixes #18571 Closes #17622 Test Plan: - Built Android AAR with QNN support (SDK 2.37) — jni_layer_llama.cpp compiles cleanly with both Runner<uint8_t> and Runner<uint16_t> template instantiations - Unit tests pass (gradlew testDebugUnitTest)
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/18731
Note: Links to docs will display an error until the docs builds have been completed. This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Runner<uint16_t>, but models can use either 8-bit or 16-bit KV cachesget_kv_io_bit_widthfrom the model (mirroringqnn_llama_runner.cpp) and instantiates the correctRunner<uint8_t>orRunner<uint16_t>temperature_to the Runner constructor (was previously omitted)Fixes #18571
Closes #17622
Test plan
jni_layer_llama.cppcompiles cleanly with both template instantiationstestDebugUnitTest)cc @cccclai @kirklandsign @infil00p